<template>
  <div class="bt_input">
    <div class="enabel" v-if="isShow">
      <textarea
        @blur="hideTextarea"
        ref="textarea"
        rows="3"
        v-model="content"
      ></textarea>
      <div class="btn_send" @click="send">发送</div>
    </div>
    <div class="disble" v-if="!isShow">
      <input type="text" @focus="isShowTextarea" :value="content" />
      <div class="pinlun">
        <span class="iconfont icon-pinglun"></span>
        <div class="num">1020</div>
      </div>
      <span class="iconfont icon-shoucang-copy"></span>
      <span class="iconfont icon-share"></span>
    </div>
  </div>
</template>

<script>
export default {
  props: ["parent"],
  data() {
    return {
      isShow: false,

      content: "",
    };
  },
  methods: {
    isShowTextarea() {
      this.isShow = !this.isShow;
      // 自动聚焦
      this.$nextTick(() => {
        this.$refs.textarea.focus();
      });
    },
    hideTextarea() {
      setTimeout(() => {
        this.isShow = false;
      }, 50);
    },
    // 发布评论
    send() {
      let data = {
        content: this.content,
      };
      if (this.parentId) {
        data.parent_id = this.parentId;
      }
      const { id } = this.$route.params;
      console.log(id);
      if (this.content.trim() === "") return;
      this.$axios({
        url: "/post_comment/" + id,
        method: "POST",
        data,
      }).then((res) => {
        console.log(res);
        if (res.data.message === "评论发布成功") {
          this.content = "";
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.bt_input {
  .enabel {
    padding: 20px;
    display: flex;
    align-items: flex-end;
    textarea {
      padding: 5px 10px;
      flex: 1;
      background-color: #d7d7d7;
      border-radius: 10px;
      outline: none;
      border: none;
      resize: none;
    }
    .btn_send {
      width: 55px;
      height: 16px;
      line-height: 16px;
      text-align: center;
      color: #fff;
      background-color: red;
      margin: 0 10px;
      padding: 4px 6px;
      border-radius: 8px;
    }
  }
  width: 100%;
  padding: 10px;
  position: fixed;
  bottom: 0;
  left: 0;
  .disble {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8.333vw 0 5.556vw;
    input {
      width: 50vw;
      height: 8.333vw;
      border-radius: 4.167vw;
      border: none;
      outline: none;
      background-color: #d7d7d7;
      padding: 0 20px;
      box-sizing: border-box;
    }
    .iconfont {
      font-size: 6.111vw;
    }
  }
  .pinlun {
    position: relative;
    .num {
      position: absolute;
      padding: 0 5px;
      color: #fff;
      border-radius: 10px;
      top: -6px;
      left: 3px;
      font-size: 12px;
      background-color: red;
    }
  }
}
</style>
